package com.qiyadeng.thread;

public class Counter {

	static long count;
	
	public synchronized void add(long value){
		System.out.println(Thread.currentThread().getName()+" enter method add");
		try {
			Thread.currentThread().sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		count += value;
		System.out.println(Thread.currentThread().getName()+ " perpare exit method:"+count);
	}
	
	public synchronized void sub(long value){
		System.out.println(Thread.currentThread().getName()+" enter method sub");
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(Thread.currentThread().getName()+" exit method sub" + count);
	}
}
